<!--header-->
<!--# include virtual="/ceca_two/common/html/header.html"-->
<link rel="stylesheet" href="/ceca_two/css/supplierInfomation.css" />
<link rel="stylesheet" href="/ceca_two/css/screeningResults.css" />
<style>
	.materiaTextImg{
		width: 106px;
		height: 106px;
	}
	.tax_price{
		max-width: 80px;
		display: block;
	}
	.no_tax_price{
		max-width: 80px;
		display: none;
	}
	.price_box .tax_price{
		display: none;
	}
	.price_box .no_tax_price{
		display: block;
	}
	.price_btn,.info_btn{    
		display: inline-block;
    	height: 26px;
    	width: 50px;
    	vertical-align: middle;
		background: url(/ceca_two/img/icon_marketprice.png) no-repeat 0 5px;
		cursor: pointer;
	}
	.price_box .price_btn,.info_box .info_btn{
		background-position: 0 -24px;
	}
	
	.content .materialTable{
		position: relative;
		margin-top: 0;
	}
	.w160{
		min-width: 160px;
		position: absolute;
		top: 0;
		line-height: 1em;
	}
	.h80{
		height: 32px;
	}
	.info_name{
		display: none;
	}
	.no_info_name{
		display: block;
	}
	.info_box .info_name{
		display: block;
	}
	.info_box .no_info_name{
		display: none;
	}
	.leftDiv{
		float: left;
	}
	table tbody td{
		text-align: center;
		height: 50px;
		line-height: 50px;
		padding: 0;
		white-space: nowrap;
		overflow: hidden;
		
	}
	.w120{
		max-width: 166px;
	}
	table tbody{
		background: #FFFFFF;
	}
	.materialCName{
		height: 210px;
		white-space: initial;
	}
	.materialCName .leftDiv{
		padding: 20px;
	}
	.materialCName .leftBot{
		margin-top: 20px;
		font-size: 12px;
		color: #999999;
		height: initial;
		line-height: initial;
	}
	.materialCName .rightDiv{
		height: initial;
		line-height: initial;
		font-size: 12px;
	}
	.materialCName .rightDiv .TextName{
		color: #0032d2;
	}
	.with_border{
		border: 1px solid #ff3030;
		color: #ff3030;
		display: inline-block;
		padding: 4px;
		line-height: initial;
		margin-top: 6px;
		background: #FFFFFF;
		border-radius: 4px;
		cursor: pointer;
	}
	.with_border a{
		color: #ff3030;
		font-size: 16px;
	}
	.with_border a:hover{
		color: #ff3030;
	}
</style>
<!--banner-->
<!--# include virtual="/ceca_two/common/html/banner.html"-->
<div class="content">
<!--# include virtual="/ceca_two/modules/market/base/navClassify.html"-->
	<div class="screenList">
		<ul class="screenTop" id="searchList">
			<li>全部分类</li>
			<li>&gt;</li>
			<li id="firstSear"></li>
			<li id="lastSear"></li>
			<li class="clearSearch">清空筛选条件</li>
		</ul>
		<div class="accordionList"  id="marketFilterHtml"></div>
	</div>
	<div class="technologyNav">
		<ul class="technologyNavUl">
			<!--<li>技术参数</li>
			<li>会员分享</li>
			<li>企业采集</li>-->
			<!--<li><span>价格</span><span class="top"></span><span class="bottom"></span></li>-->
			<!--<li><span>发布时间</span><span class="top"></span><span class="bottom"></li>-->
			<!--<li>平台登记时间<span class="top"></span><span class="bottom"></li>-->
			<li>为您找到 <span id="totalRow" style="color: red;">0</span> 条结果</li>
		</ul>
	</div>
	<table border="0" cellspacing="0" cellpadding="0" class="materialTable">
		<thead>
			<tr class="materialName">
				<td rowspan="2" width="28%">材料名称及规格</td>
				<td rowspan="2" width="8%">品牌</td>
				<td rowspan="2" width="14%">产品系列</td>
				<td rowspan="2" width="8%">单位</td>
				<td colspan="2" width="14%">
					<div class="h80">
						<p class="w160">除税价<em class="price_btn"></em>含税价</p>
					</div>
				</td>
				<td rowspan="2" width="14%" style="max-width: 166px;">
					<div class="h80" style="display: inline-block;width: 166px;">
						<p class="w160" style="top: 12px;min-width: 166px;">信息商<em class="info_btn"></em>材料商</p>
					</div>
				</td>
				<!--<td rowspan="2" width="12%">纳税性质</td>-->
				<td rowspan="2" width="14%">采集日期</td>
			</tr>
			<tr class="materialName Name">
				<td width="7%">最高</td>
				<td width="7%">最低</td>
			</tr>
		</thead>
		<tbody id="materialContent">
			
		</tbody>
	</table>
	<!--<div class="materialContent" ></div>-->
	<div id="laypage" style="margin-left: inherit;" ></div>	
</div>
<!--底部-->
<!--# include virtual="/ceca_two/common/html/footer.html"-->
<script id="material" type="text/html">
	{{# layui.each(d, function(index, item){ }}
		<tr style="border-top: 1px solid #CCCCCC;">
			<td rowspan="4">
				<div class="materialCName" style="width: 226px;">
					<div class="leftDiv">
						<img src="{{ item.imgUrl ||  item.commomImgUrl || '/ceca_two/img/prdt_mpic.png' }} " class="materiaTextImg"/>
						<div class="leftBot">
							<!--<input type="checkbox" class="TextChk" id="TextChk1"/>-->
							<!--<label for="TextChk1" class="TextLbl">加入对比</label>-->
						</div>
					</div><div class="rightDiv" style="width: 80px;height: auto;display: inline-block;vertical-align: middle;float: none;margin-top: 50px;">
						<h1 class="TextName" style="font-size: 18px;font-family: '黑体';">{{ item.materialName}}</h1>
						<p class="TextStandard">
							{{#  layui.each(JSON.parse(item.specificcations), function(index, its){ }}
							    
								{{#  layui.each(its, function(i, it){ }}
									{{# if(i!="品种"){ }}
									{{ it }}
									{{# } }}
								{{# }) }}
							{{# }) }}
				        </p>
					</div>
				</div>
			</td>
			<!--<div class="flright">-->
				{{#  layui.each(item.doc, function(i, it){ }}
					{{# if(i!=0){  }}
						<tr>
					{{# } }}
					<!--<ul class="materialCText">-->
						<td>{{# if(it.brand){  }}{{it.brand}}{{# } }}</td>
						<td>{{# if(it.productLine){  }}{{it.productLine}}{{# } }}</td>
						<td>{{# if(it.units){  }}{{it.units}}{{# } }}</td>
						<td>
							<span class="tax_price">{{# if(it.maxTaxPrice){  }}{{it.maxTaxPrice}}{{# } }}</span>
							<span class="no_tax_price">{{# if(it.maxNoTaxPrice){  }}{{it.maxNoTaxPrice}}{{# } }}</span>
						</td>
						<td>
							<span class="tax_price">{{# if(it.maxTaxPrice){  }}{{it.maxTaxPrice}}{{# } }}</span>
							<span class="no_tax_price">{{# if(it.minNoTaxPrice){  }}{{it.minNoTaxPrice}}{{# } }}</span>
						</td>
						<td class="w120">
							<span class="no_info_name">{{# if(it.supplierName){  }}{{it.supplierName}}{{# } }}</span>
							<span class="info_name">{{# if(it.infoSupplierName){  }}{{it.infoSupplierName}}{{# } }}</span>
						</td>
						<!--<td>{{# if(it.supplierNature){  }}{{it.supplierNature}}{{# } }}</td>-->
						<td>{{# if(it.quotationDate){  }}{{it.quotationDate}}{{# } }}</td>
					</tr>
				{{# }); }}
			{{# if(item.doc.length>0){ }}
				<tr>
			{{# } }}
				<td colspan="7">
					<p onclick="window.open('/ceca_two/modules/market/offerDetails.html?'+window.location.search+'&categoryId={{item.categoryId}}')"   class="materialCText" style="text-align: center;">
						<a style="cursor: pointer;" class="look">共<span>{{item.numFound }}</span>条报价，<span>查看全部</span></a>
					</p>
				</td>
			</tr>
			{{# if(item.doc.length<=0){ }}
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			{{#}else if(item.doc.length<=1){}}
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			{{#}else if(item.doc.length<=2){}}
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<!--<td></td>-->
				<td></td>
			</tr>
			{{#}}}
	{{# }); }}
</script>
<script id="marketFilterTemplate" type="text/html">
{{#  $.each(d, function(index, item){ }}
	{{#  layui.each(item, function(arrIndex, arrItem){ }}
		<div class="accordionListText" data-value="{{ arrIndex }}">
			<div class="accordionListName">
				{{# if(arrIndex =='materialName'){ arrIndex="材料名称:"; } }}
				{{# if(arrIndex =='categoryName'){ arrIndex="分类名称:"; } }}
				{{# if(arrIndex =='supplierName'){ arrIndex="材料供应商:"; } }}
				{{# if(arrIndex =='brand'){ arrIndex="品牌:"; } }}
				{{ arrIndex }}
			</div>
			<ul class="accordionListUl">
				{{#  layui.each(arrItem, function(aIndex, aItem){ }}
				<li>{{aItem}}</li>
				{{# }); }}
			</ul>
			<p class="more" style="position: relative;float: right;">
				<span class="moreIn" style="position: absolute;right: 30px;height: auto;">></span>
				<span class="moreText">更多</span>
			</p>
		</div>
	{{# }); }}
{{# }); }}
</script>
<script>
layui.use(['Router','Zarea','Zutil','market','laytpl','laypage'], function() {
	var Router = layui.Router;
	var Zarea = layui.Zarea;
	var Zutil = layui.Zutil;
	var market= layui.market;
	var laytpl= layui.laytpl;
	var laypage= layui.laypage;
	
	var Url = Router.link.materialPrice.searchMarketInfo;
    var filterUrl = Router.link.materialPrice.searchMarketFilter;
    
	var search=Zutil.decodeURI(window.atob(Zutil.getQueryString("search")  || ""));
	var areaCode=Zutil.getQueryString("areaCode");
	var materialName=Zutil.decodeURI(window.atob(Zutil.getQueryString("materialName") || ""));
	var categoryName=Zutil.decodeURI(window.atob(Zutil.getQueryString("categoryName") || ""));
	var supplierName=Zutil.decodeURI(window.atob(Zutil.getQueryString("supplierName") || ""));
	var specificcations=Zutil.decodeURI(window.atob(Zutil.getQueryString("specificcations")  || ""));
	var brand=Zutil.decodeURI(window.atob(Zutil.getQueryString("brand") || ""));
	var pageNumber=Zutil.getQueryString("pageNumber")  || 1;
	var pageSize=Zutil.getQueryString("pageSize") || 10;
	
	var searchObj={
		search:search,
		areaCode:areaCode,
		materialName:materialName,
		categoryName:categoryName,
		supplierName:supplierName,
		specificcations:specificcations,
		brand:brand,
		pageNumber:pageNumber,
		pageSize:pageSize
	};
	function data2url(){
		var base =window.location.pathname+"?";
		if(searchObj.search && searchObj.search.length >0)base+="&search="+window.btoa(Zutil.encodeURI(searchObj.search));
		if(searchObj.areaCode && searchObj.areaCode.length >0)base+="&areaCode="+searchObj.areaCode;
		if(searchObj.materialName && searchObj.materialName.length >0)base+="&materialName="+window.btoa(Zutil.encodeURI(searchObj.materialName));
		if(searchObj.categoryName && searchObj.categoryName.length >0)base+="&categoryName="+window.btoa(Zutil.encodeURI(searchObj.categoryName));
		if(searchObj.supplierName && searchObj.supplierName.length >0)base+="&supplierName="+window.btoa(Zutil.encodeURI(searchObj.supplierName));
		if(searchObj.specificcations && searchObj.specificcations.length >0)base+="&specificcations="+window.btoa(Zutil.encodeURI(searchObj.specificcations));
		if(searchObj.brand && searchObj.brand.length >0)base+="&brand="+window.btoa(Zutil.encodeURI(searchObj.brand));
		if(searchObj.pageNumber && (searchObj.pageNumber+"").length >0)base+="&pageNumber="+searchObj.pageNumber;
		if(searchObj.pageSize && (searchObj.pageSize+"").length >0)base+="&pageSize="+searchObj.pageSize;
		return base;
	}
	$(".ClassiftInput").val(searchObj.search);
	
	
	
	var navUrl = Router.link.materialPrice.getMarketCategory;
	var laypage= layui.laypage;
	var nameObj={};
	$.post(navUrl,{},function(result){
		var  data = result.data;
		var finalData=[];
		var datalength;
		var temp;
		for(var i=0;i<data.length;i++){
			if(data[i].categoryParentId=="1"){
				temp=data[i];
				temp["sonlassift"]=[];
				finalData.push(temp);
			}
			nameObj[data[i].categoryName]=data[i];
//			data[i]["sonlassift"]=data;
		}
		searchFunc(false);
		for(var i=0;i<finalData.length;i++){
			for(var j=0;j<data.length;j++){
				if(data[j].categoryParentId==finalData[i].categoryId){
					finalData[i]["sonlassift"].push(data[j]);
				}
			}
		}
		laytpl(classiftItem.innerHTML).render(finalData, function(html){
			classiftBox.innerHTML = html;
			$(".classiftListNext li").click(function(){
				var categoryName =window.btoa(Zutil.encodeURI($(this).attr("data-categoryName") || ""));
				window.location.href='/ceca_two/modules/market/screeningResults.html?areaCode='+Zutil.getQueryString("areaCode")+'&categoryName='+categoryName
			});
		});
		
	});
	
	
	
	
	function getList(obj){
		$.post(Url,searchObj,function(result){
			if( result.data.list && result.data.list.length > 0  ){
                var data = result.data;
                laytpl(material.innerHTML).render(data.list, function(html){
                    materialContent.innerHTML = html;
                    laypage({
                        cont: 'laypage'
                        ,pages: data.totalPage
                        ,curr:data.pageNumber
                        ,groups:data.pageSize
                        ,skin: '#ff0000'
                        ,jump: function(opt, first){
                            var curr = opt.curr;   //得到了当前页，用于向服务端请求对应数据
                            searchObj.pageNumber = curr|| 1;
                            searchObj.pageSize = data.pageSize;
                            if(!first){
                                window.location.href = data2url();
                            }
                        }
                    });
                });
                $("#totalRow").html(data.totalRow);
			}else{
                $("#materialContent").empty().append("<tr><td colspan='9'>" +
                    "<h1 style='width: 100%;text-align: center;font-size: 30px;background: #fff;padding: 50px; margin: 35px 0;'>暂无相关信息</h1>" +
                    "</td></tr>")
            }
		});
	}
	function marketFilter(obj){
		$.post(filterUrl,obj,function(result){
			console.log(result);
			if(result.data){
                var  data = result.data;
                laytpl(marketFilterTemplate.innerHTML).render(data, function(html){
                    marketFilterHtml.innerHTML = html;
                });
                var  ext =result.ext;
                var tempObj={};
                var html="";
                if(ext && ext.length >0){

                    for(var j in ext){
                        $.each(jQuery.parseJSON(ext[j]), function(key,val) {
                            if(key =="specificcations"){
                                var specificcations =jQuery.parseJSON(val);
                                $.each(specificcations, function(k,v){
                                    html+='<li class="with_border"  data-key='+k+' data-value='+v+'>';
                                    html+=k+"："+v;
                                    html+='<a>×</a></li>';
                                });
                            }else{
                                html+='<li class="with_border"  data-key='+key+' data-value='+val+'>';
                                if(key =="categoryName"){
                                    key="分类名称";
                                    tempObj["分类名称"]=val;
                                }
                                if(key =="brand")key="品牌";
                                if(key=="supplierName")key="材料供应商";
//							if(key=="materialName")key="材料名称";
                                if(key =="materialName"){
                                    key="材料名称";
                                    tempObj["材料名称"]=val;
                                }
                                html+=key+"："+val;
                                html+='<a>×</a></li>';
                            }
                        });
                    }
                    var categoryNameTxt="";
                    var categoryObj;
                    if((obj.search)&&(nameObj[obj.search])){
                        categoryObj=nameObj[obj.search];
                        if(categoryObj.level==4){
                            if(!(tempObj["材料名称"])){
                                html+='<li class="with_border"  data-key=材料名称 data-value='+categoryObj.materialName+'>';
                                html+="材料名称："+categoryObj.categoryName;
                            }
                        }else if(categoryObj.level==3){
                            if(!(tempObj["分类名称"])){
                                html+='<li class="with_border"  data-key=材料名称 data-value='+categoryObj.categoryName+'>';
                                html+="分类名称："+categoryObj.categoryName;
                            }
                        }
                        html+='<a>×</a></li>';
                    }
                    $.each($(".with_border"), function(key,val) {
                        var dataKey=$(this).attr("data-key");
                        $.each($(".accordionListText"), function(k,v) {
                            if($(this).attr("data-value")==dataKey)$(this).remove();
                        });
                    });
                }else{
                    var categoryNameTxt="";
                    var categoryObj;
                    if((obj.search)&&(nameObj[obj.search])){
                        categoryObj=nameObj[obj.search];
                        if(categoryObj.level==4){
                            html+='<li class="with_border"  data-key=材料名称  data-value='+categoryObj.materialName+'>';
                            html+="材料名称："+categoryObj.categoryName;
                        }else if(categoryObj.level==3){
                            html+='<li class="with_border"  data-key=分类名称  data-value='+categoryObj.categoryName+'>';
                            html+="分类名称："+categoryObj.categoryName;
                        }
                        html+='<a>×</a></li>';
                    }
                }

                $("#lastSear").after(html);
			}else{

                $("#materialContent").empty().append("<tr><td colspan='9'>" +
					"<h1 style='width: 100%;text-align: center;font-size: 30px;background: #fff;padding: 50px; margin: 35px 0;'>暂无相关信息</h1>" +
					"</td></tr>")
            }
		});
	}
	
	$(".ClassiftBtn").click(searchFunc);
	$(".ClassiftInput").keydown(function(event){
		var e = event || window.event || arguments.callee.caller.arguments[0];
		if(e && e.keyCode==13){ // enter 键
            searchFunc();
        }
	});
	
	function searchFunc(flag){
		var search = $("input[name='search']").val().trim();
		if((!search)&&(flag)){
			return;
		}
		if(search)searchObj.search=search;
		getList(searchObj);
		marketFilter(searchObj);
	}
	$(".price_btn").click(function(){
		if($(".content").hasClass("price_box")){
			$(".content").removeClass("price_box");
		}else{
			$(".content").addClass("price_box");
		}
	});
	$(".info_btn").click(function(){
		if($(".content").hasClass("info_box")){
			$(".content").removeClass("info_box");
		}else{
			$(".content").addClass("info_box");
		}
	});
	$(document).on("click",".accordionListUl li",function(){
		var nameStr=$(this).parents(".accordionListText").attr("data-value");
		$("#lastSear").after("<li class='with_border' data-key='"+nameStr+"' data-value='"+$(this).html()+"'>"+$(this).parent("ul").siblings(".accordionListName").html()+":"+$(this).html()+"<a>×</a></li>");
		var length=$(".with_border").length;
		for(var i=0;i<length;i++){
			if(searchObj[$(".with_border").eq(i).attr("data-key")]){
				searchObj[$(".with_border").eq(i).attr("data-key")]=$(".with_border").eq(i).attr("data-value");
			}else{
				var key =$(".with_border").eq(i).attr("data-key");
				var value=$(".with_border").eq(i).attr("data-value");
				if(key=="categoryName"){
					searchObj.categoryName=value;
				}else if(key=="materialName"){
					searchObj.materialName=value;
				}else if(key=="supplierName"){
					searchObj.supplierName=value;
				}else if(key=="brand"){
					searchObj.brand=value;
				}else{
					var newData ={};
					newData[key] =value;
					if(searchObj.specificcations && searchObj.specificcations.length>0 ){
						searchObj.specificcations =JSON.stringify($.extend(jQuery.parseJSON(searchObj.specificcations),newData));
					}else{
						searchObj.specificcations =JSON.stringify($.extend({},newData));
					}
				}
			}
		}
		$(this).remove();
		window.location.href = data2url();
	});
	$(".clearSearch").click(function(){
		$(".with_border").remove();
		delete searchObj.materialName;
		delete searchObj.categoryName;
		delete searchObj.supplierName;
		delete searchObj.specificcations;
		delete searchObj.brand;
		delete searchObj.pageNumber;
		delete searchObj.pageSize;
		window.location.href = data2url();
	});
	$(document).on("click",".with_border",function(){
		var dkey=$(this).attr("data-key");
		delete searchObj[dkey];
		if(searchObj.specificcations.length >0){
			var  specificcations = jQuery.parseJSON(searchObj.specificcations);
			delete  specificcations[dkey];
			searchObj.specificcations =JSON.stringify(specificcations);
		}
		searchObj.search=$.trim($(".ClassiftInput").val());
		$(this).remove();
		window.location.href = data2url();
	});
});
</script>
</body>
</html>
